package com.service;

import com.bean.Courier;
import com.dao.BaseCourierDao;
import com.dao.impl.CourierDaoMysql;
import com.exception.DuplicateUserPhoneException;

import java.util.List;
import java.util.Map;

public class CourierService {
    BaseCourierDao baseCourierDao = new CourierDaoMysql();

    public List<Map<String, Integer>> console() {
        return baseCourierDao.console();
    }


    public List<Courier> findAll(boolean limit, int offset, int pageNumber) {
        return baseCourierDao.findAll(limit, offset, pageNumber);
    }

    public Courier findByPhone(String userPhone) {
        return baseCourierDao.findByPhone(userPhone);
    }

    public boolean insert(Courier courier) {
        try {
            boolean flag = baseCourierDao.insert(courier);
            if (flag) {
                //SMSUtil.send(e.getUserPhone(), e.getCode());
            }
            return flag;
        } catch (DuplicateUserPhoneException duplicateUserPhoneException) {
            return false;
        }
    }

    public boolean update(int id, Courier courier) {
        try {
            boolean flag = baseCourierDao.update(id, courier);
            if (flag) {
                //SMSUtil.send(e.getUserPhone(), e.getCode());
            }
            return flag;
        } catch (DuplicateUserPhoneException duplicateUserPhoneException) {
            return false;
        }
    }

    public boolean updateLastLoginTime(String userPhone) {
        return baseCourierDao.updateLastLoginTime(userPhone);
    }

    public boolean delete(int id) {
        return baseCourierDao.delete(id);
    }
}
